<?php
	require_once($_SERVER['DOCUMENT_ROOT']."/classes/Account.class.php");
	require_once($_SERVER['DOCUMENT_ROOT']."/includes/sugar.php");
	session_start();
	if(md5($_POST['oldPass']) != $_SESSION['account']->password){
		$array['errMess'] = getErrMess(3);
		$array['status'] = 0;
		$array['link'] = "http://".$_SERVER['SERVER_NAME']."/index.php?module=myaccount&errcode=3";
	}
	else
	{
		if($_POST['newPass'] != $_POST['confirmPass']){
			$array['errMess'] = getErrMess(2);
			$array['status'] = 0;
		}else{
			if(strlen($_POST['newPass']) < 4){
				$array['errMess'] = getErrMess(22);
				$array['status'] = 0;
			}
			else
			{
				$status = ($_SESSION['account']->isConfirmed == 1)? 0:1;
				if($_SESSION['account']->confirm($_POST['newPass']) > 0){
					$array['errMess'] = getErrMess(4);
					$array['status'] = $status;
					$array['link'] = "http://".$_SERVER['SERVER_NAME']."/index.php?module=myaccount&errcode=4";
				}
				else
				{
					$array['errMess'] = getErrMess(5);
					$array['status'] = 0;
				}
			}
		}
	}
	echo json_encode($array);
?>